$(document).ready(function(){
//	var file =new Image();
//	file.src = carouselUrl;
//	var chat_top=$(window).height()/$(window).width()*file.width;
	var chat_top = $('.chat').offset().top;
//	//console.info(chat_top);
	$('.chat').css('height',$(window).height()-chat_top-50+'px');
	function imgLoaded(){
		var img=$('.swiper-slide').eq(0).find('img');
		if(img.get(0).complete){
			var chat_top = $('.chat').offset().top;
			$('.chat').css('height',$(window).height()-chat_top-50+'px');
			clearInterval(loading);
		}					
	}
	var loading=setInterval(imgLoaded,100);
})
$(function(){
				if(timtout>staggerTime){
					getChatJsonFirst();//第一次登陆获取json的内容
				}
				getSpecialJsonTime();//时间规则
				getSpecialJsonNum();//条数规则
				getSpecialJsonEveryDay();
				getSpecialJsonOneTime();
				getSpecialAdJSON();//特殊广告
				$('a.alert-btn').click(function (e) {
		    		$('div.alert').hide();
		    		$('.mask_zzc').hide();
		    	});
				setTimeout(function(){
						getChatJson();
						setInterval('getChatJson()',refreshtime);
					},timtout);
		    	
//				
	});
			function showMsg(msg){
	    		$("#msg").text(msg);
				$('#alert2').show();
				$('.mask_zzc').show();
	    	}
			//特殊弹幕 条数规则
			function getSpecialJsonNum(){
				var html="";
				for (var o in rule2) {
					//var top = 0.4*Math.random();
					var speed = 8*(Math.random()+1);
					var delay = 10+8*(Math.random()+1);
//					html=html+"<div onClick=\"javascript:window.location.href=\'"+rule2[o].source_url+"\' \" class='golden1 fly1 fly-moveFromLeft'";
//					html=html+"style='z-index:1600;top:"+top*92+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
//					html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;background-color:#"+rule2[o].background_color+";' >";
//					html=html+"<div class='border_span_img'>";
//					html=html+"<img src='/ws"+rule2[o].pic_url+"'>";
//					html=html+"<span  class='chat-content'>"+rule2[o].title+"</span>";
//					html=html+"</div>";
//					html=html+"</div>";
					if(rule2[o].color==""||rule2[o].color==null){
						html = html+"<ul class='golden fly fly-moveFromLeft'";
					}else{
						html = html+"<ul class='"+rule2[o].color+" fly fly-moveFromLeft'";
					}
					if(rule2[o].group_id!=null&&rule2[o].group_id!=0){
						html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule2[o].group_id+"\')\" ";
					}else{
						html = html+" onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\" ";
					}
					html=html+"style='z-index:1600;top:"+rule2[o].top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
					html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
					html=html+"<li><img src='/ws"+rule2[o].pic_url+"'></li>";
					html = html+"<li><span class='chat-content'>"+rule2[o].title+"</span></li>";
//					if(rule2[o].group_id!=null&&rule2[o].group_id!=0){
//						html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule2[o].group_id+"\')\" ><span class='chat-content'>"+rule2[o].title+"</span></li>";
//					}else{
//						html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\"><span class='chat-content'>"+rule2[o].title+"</span></li>";
//					}
//					html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\" onClick=\"javascript:window.location.href=\'"+rule2[o].source_url+"\' \"><span class='chat-content'>"+rule2[o].title+"</span></li>";
					html=html+"<li></li>";
					html=html+"</ul>";
					}
				$(".chat").append(html);
			}
			//特殊弹幕 时间规则
			function getSpecialJsonTime(){
				var html="";
				var top = 0;
				for (var o in rule) {
//					if(top>=0.75){
//						top=0.25;
//					}else{
//						top +=0.25;
//					}
				//	var top = 0.8*Math.random();
					var speed = 8*(Math.random()+1);
					var delay = rule[o].showtime;
//					html=html+"<div onClick='javascript:window.location.href=\""+rule[o].source_url+"\" ' class='golden1 fly1 fly-moveFromLeft'";
//					html=html+"style='z-index:1600;top:"+top*100+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
//					html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;background-color:#"+rule[o].background_color+";' >";//background-color:#"+rule[o].background_color+";
//					html=html+"<div class='border_span_img'>";
//					html=html+"<img src='/ws"+rule[o].pic_url+"'>";
//					html=html+"<span  class='chat-content'>"+rule[o].title+"</span>";
//					html=html+"</div>";
//					html=html+"</div>";
					if(rule[o].color==""||rule[o].color==null){
						html = html+"<ul class='golden fly fly-moveFromLeft'";
					}else{
						html = html+"<ul class='"+rule[o].color+" fly fly-moveFromLeft'";
					}
					if(rule[o].group_id!=null&&rule[o].group_id!=0){
						html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule[o].group_id+"\')\" ";
					}else{
						html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule[o].group_id+"\')\" ";
					}
					html=html+"style='z-index:1600;top:"+rule[o].top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
					html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
					html=html+"<li><img src='/ws"+rule[o].pic_url+"'></li>";
					html = html+"<li><span class='chat-content'>"+rule[o].title+"</span></li>";
//					if(rule[o].group_id!=null&&rule[o].group_id!=0){
//						html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule[o].group_id+"\')\" ><span class='chat-content'>"+rule[o].title+"</span></li>";
//					}else{
//						html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule[o].source_url+"\')\" ><span class='chat-content'>"+rule[o].title+"</span></li>";
//					}
//					html = html+"<li  onClick=\"javascript:window.location.href=\'"+rule[o].source_url+"\' \" ><span class='chat-content'>"+rule[o].title+"</span></li>";
					html=html+"<li></li>";
					html=html+"</ul>";
					}
					$(".chat").append(html);
			}
			
			function getSpecialJsonEveryDay(){//每日
				var html="";
				for (var o in rule3) {
					//var top = 0.4*Math.random()+0.4*Math.random();
					var speed = 8*(Math.random()+1);
					var specific_time = parseInt(rule3[o].specific_time)*1000;
					if(specific_time>=now){
						if(rule3[o].time!=1){
							var top = rule3[o].top;
							for(var int=0;int<rule3[o].time;int++){
								var delay  = (specific_time-now)/1000+int;
								if(rule3[o].color==""||rule3[o].color==null){
									html = html+"<ul class='golden fly fly-moveFromLeft'";
								}else{
									html = html+"<ul class='"+rule3[o].color+" fly fly-moveFromLeft'";
								}
								if(rule3[o].group_id!=null&&rule3[o].group_id!=0){
									html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule3[o].group_id+"\')\" ";
								}else{
									html = html+" onClick=\"toSpecialUrl(this,\'"+rule3[o].source_url+"\')\" ";
								}
								html=html+"style='z-index:1600;top:"+top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
								html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
								html=html+"<li><img src='/ws"+rule3[o].pic_url+"'></li>";
								html = html+"<li><span class='chat-content'>"+rule3[o].title+"</span></li>";
//								if(rule3[o].group_id!=null&&rule3[o].group_id!=0){
//									html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule3[o].group_id+"\')\" ><span class='chat-content'>"+rule3[o].title+"</span></li>";
//								}else{
//									html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule3[o].source_url+"\')\"><span class='chat-content'>"+rule3[o].title+'</span></li>';
//								}
//								html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\" onClick=\"javascript:window.location.href=\'"+rule3[o].source_url+"\' \"><span class='chat-content'>"+rule3[o].title+'</span></li>';
								html=html+"<li></li>";
								html=html+"</ul>";
								top=top+15;
								if(top>=85){
									top=1;
								}
							}
						}else{
							var delay  = (specific_time-now)/1000;
//							html=html+"<div onClick='javascript:window.location.href=\""+rule3[o].source_url+"\" ' class='golden1 fly1 fly-moveFromLeft'";
//							html=html+"style='z-index:1600;top:"+top*100+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
//							html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;background-color:#"+rule3[o].background_color+";' >";//background-color:#"+rule[o].background_color+";
//							html=html+"<div class='border_span_img'>";
//							html=html+"<img src='/ws"+rule3[o].pic_url+"'>";
//							html=html+"<span  class='chat-content'>"+rule3[o].title+"</span>";
//							html=html+"</div>";
//							html=html+"</div>";
							if(rule3[o].color==""||rule3[o].color==null){
								html = html+"<ul class='golden fly fly-moveFromLeft'";
							}else{
								html = html+"<ul class='"+rule3[o].color+" fly fly-moveFromLeft'";
							}
							if(rule3[o].group_id!=null&&rule3[o].group_id!=0){
								html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule3[o].group_id+"\')\" ";
							}else{
								html = html+" onClick=\"toSpecialUrl(this,\'"+rule3[o].source_url+"\')\" ";
							}
							html=html+"style='z-index:1600;top:"+rule3[o].top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
							html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
							html=html+"<li><img src='/ws"+rule3[o].pic_url+"'></li>";
							html = html+"<li ><span class='chat-content'>"+rule3[o].title+"</span></li>";
//							if(rule3[o].group_id!=null&&rule3[o].group_id!=0){
//								html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule3[o].group_id+"\')\" ><span class='chat-content'>"+rule3[o].title+"</span></li>";
//							}else{
//								html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule3[o].source_url+"\')\"><span class='chat-content'>"+rule3[o].title+'</span></li>';
//							}
//							html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\" onClick=\"javascript:window.location.href=\'"+rule3[o].source_url+"\' \"><span class='chat-content'>"+rule3[o].title+'</span></li>';
							html=html+"<li></li>";
							html=html+"</ul>";
						}
						
					}
				}
					$(".chat").append(html);
			}
			function getSpecialJsonOneTime(){
				var html="";
				for (var o in rule4) {
					var top = 0.2*Math.random()+0.3*Math.random();
					var speed = 8*(Math.random()+1);
					var specific_time = parseInt(rule4[o].specific_time)*1000;
					if(specific_time>=now){
						if(rule4[o].time!=1){
							var top = rule4[o].top;
							for(var int=0;int<rule4[o].time;int++){
								var delay  = (specific_time-now)/1000+int;
								if(rule4[o].color==""||rule4[o].color==null){
									html = html+"<ul class='golden fly fly-moveFromLeft'";
								}else{
									html = html+"<ul class='"+rule4[o].color+" fly fly-moveFromLeft'";
								}
								if(rule4[o].group_id!=null&&rule4[o].group_id!=0){
									html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule4[o].group_id+"\')\" ";
								}else{
									html = html+" onClick=\"toSpecialUrl(this,\'"+rule4[o].source_url+"\')\" ";
								}
								
								html=html+"style='z-index:1600;top:"+top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
								html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
								html=html+"<li><img src='/ws"+rule4[o].pic_url+"'></li>";
								html = html+"<li><span class='chat-content'>"+rule4[o].title+"</span></li>";
//								if(rule4[o].group_id!=null&&rule4[o].group_id!=0){
//									html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule4[o].group_id+"\')\" ><span class='chat-content'>"+rule4[o].title+"</span></li>";
//								}else{
//									html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule4[o].source_url+"\')\"><span class='chat-content'>"+rule4[o].title+'</span></li>';
//								}
								html=html+"<li></li>";
								html=html+"</ul>";
								top=top+15;
								if(top>=85){
									top=1;
								}
							}
						}else{
							var delay  = (specific_time-now)/1000;
//							html=html+"<div onClick='javascript:window.location.href=\""+rule4[o].source_url+"\" ' class='golden1 fly1 fly-moveFromLeft'";
//							html=html+"style='z-index:1600;top:"+top*100+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
//							html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;background-color:#"+rule4[o].background_color+";' >";//background-color:#"+rule[o].background_color+";
//							html=html+"<div class='border_span_img'>";
//							html=html+"<img src='/ws"+rule4[o].pic_url+"'>";
//							html=html+"<span  class='chat-content'>"+rule4[o].title+"</span>";
//							html=html+"</div>";
//							html=html+"</div>";
							if(rule4[o].color==""||rule4[o].color==null){
								html = html+"<ul class='golden fly fly-moveFromLeft'";
							}else{
								html = html+"<ul class='"+rule4[o].color+" fly fly-moveFromLeft'";
							}
							if(rule4[o].group_id!=null&&rule4[o].group_id!=0){
								html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule4[o].group_id+"\')\" ";
							}else{
								html = html+" onClick=\"toSpecialUrl(this,\'"+rule4[o].source_url+"\')\" ";
							}
							html=html+"style='z-index:1600;top:"+rule3[o].top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
							html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
							html=html+"<li><img src='/ws"+rule4[o].pic_url+"'></li>";
							html = html+"<li ><span class='chat-content'>"+rule4[o].title+"</span></li>";
//							if(rule4[o].group_id!=null&&rule4[o].group_id!=0){
//								html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule4[o].group_id+"\')\" ><span class='chat-content'>"+rule4[o].title+"</span></li>";
//							}else{
//								html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule4[o].source_url+"\')\"><span class='chat-content'>"+rule4[o].title+'</span></li>';
//							}
//							html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule3[o].source_url+"\')\"  onClick=\"javascript:window.location.href=\'"+rule4[o].source_url+"\'\"><span class='chat-content'>"+rule4[o].title+'</span></li>';
							html=html+"<li></li>";
							html=html+"</ul>";
						}
					}else{
						
					}
				}
				$(".chat").append(html);
			}
			//第一次获取评论json
			function getChatJsonFirst(){
				var commentTimestamp  = Date.parse(new Date());
				var jsonurl = "/ws/chat.json?"+Math.random();
				$.getJSON(jsonurl, function(data){
					var html="";
					for (var o in data) {
						if((refreshtime-timtout)/1000<=data[o].delay){
							if(data[o].wxid!=wxid){
								var top = data[o].top+Math.random();
								var delay = data[o].delay-((refreshtime-timtout)/1000);
//								html=html+"<div class='golden fly fly-moveFromLeft'";
//								html=html+"style='top:"+top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
//								html=html+"animation-duration:"+data[o].speed+"s;-webkit-animation-duration:"+data[o].speed+"s;' >";
//								html=html+"<img src='"+data[o].headimgurl+"'>";
//								html=html+"<span class='chat-content'>"+data[o].comment+"</span>";
//								html=html+"</div>";
								
								html = html+"<ul class='normal fly fly-moveFromLeft'";
								html=html+"style='top:"+top+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
								html=html+"animation-duration:"+data[o].speed+"s;-webkit-animation-duration:"+data[o].speed+"s;' >";
								html=html+"<li><img src='"+data[o].headimgurl+"'></li>";
								html = html+'<li><span class="chat-content">'+data[o].comment+'</span></li>';
								html=html+"<li></li>";
								html=html+"</ul>";
							}
						}
						
					}
					$(".chat").append(html);
				})
			}
			//获取评论JSON数据
			function getChatJson(){
				var commentTimestamp  = Date.parse(new Date());
				var jsonurl = "/ws/chat.json?"+Math.random();
				$.getJSON(jsonurl, function(data){
					//console.info(data);
					var html="";
					for (var o in data) {
						if(data[o].wxid!=wxid){
							var top = data[o].top+Math.random();
//							html=html+"<div class='golden fly fly-moveFromLeft'";
//							html=html+"style='top:"+top+"%;animation-delay:"+data[o].delay+"s;-webkit-animation-delay:"+data[o].delay+"s;";
//							html=html+"animation-duration:"+data[o].speed+"s;-webkit-animation-duration:"+data[o].speed+"s;' >";
//							html=html+"<img src='"+data[o].headimgurl+"'>";
//							html=html+"<span class='chat-content'>"+data[o].comment+"</span>";
//							html=html+"</div>";
							html = html+"<ul class='normal fly fly-moveFromLeft'";
							html=html+"style='top:"+top+"%;animation-delay:"+data[o].delay+"s;-webkit-animation-delay:"+data[o].delay+"s;";
							html=html+"animation-duration:"+data[o].speed+"s;-webkit-animation-duration:"+data[o].speed+"s;' >";
							html=html+"<li><img src='"+data[o].headimgurl+"'></li>";
							html = html+'<li><span class="chat-content">'+data[o].comment+'</span></li>';
							html=html+"<li></li>";
							html=html+"</ul>";							
						}
					}
					$(".chat").append(html);
				})
			}
			var isSend = false;
			//发评论
			function sendComment(){
				if(isSend){
					return;
				}
				isSend =true;
				var text = $("#commont").val();
				if(text==null||text==""||text==undefined){
					showMsg("请吐槽，谢谢~");
					isSend = false;
					return false;
				}
				var length = getBLen(text);
				if(length>chatMaxNum){
					showMsg("吐槽点太多啦，少点字吧~");
					isSend = false;
					return false;
				}
				var commentTimestamp  = Date.parse(new Date());//控制多次评论
				if((commentTimestamp-now)/1000<60){
					console.info(1);
						if(number>=commentMinuteMax){
							console.info(2);
							showMsg("不要经常吐槽，这样不好~");
							isSend = false;
							return false;
						}
				}else{
					now = commentTimestamp;
					number = 0;//重新计算
				}
				if(commentDayNum>=commentDayMax){
					showMsg("今天的吐槽点已经很多，请明天在继续~");
					isSend = false;
					return false;
				}
				var url = "/ws/index.php?g=mobile&m=chat&a=saveComment"
				var data = {
					"text":text
				};
				$.post(url,data,function(data){
					isSend =false;
					if(data.error=="1"){
						number++;
						commentDayNum++;
						$("#commont").val("");
						var speed = 8*(Math.random()+1);
						var top = 0.8*Math.random();
//						var html = "<div class='golden fly fly-moveFromLeft'";
//						html=html+"style='top:"+top*100+"%;animation-delay:"+1+"s;-webkit-animation-delay:"+1+"s;";
//						html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
//						if(imgurl!=null&&imgurl!=""&&imgurl!=undefined){
//							html=html+"<img src='"+imgurl+"'>";
//						}
//						html=html+"<span  class='chat-content'>"+text+"</span>";
//						html=html+"</div>";
						var html = "<ul class='normal fly fly-moveFromLeft'";
						html=html+"style='top:"+top*100+"%;animation-delay:"+1+"s;-webkit-animation-delay:"+1+"s;";
						html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
						html=html+"<li>";
						if(imgurl!=null&&imgurl!=""&&imgurl!=undefined){
							html=html+"<img src='"+imgurl+"'>";
						}
						html=html+"</li>";
						html = html+'<li><span class="chat-content">'+text+'</span></li>';
						html=html+"<li></li>";
						html=html+"</ul>";
						
						$(".chat").append(html);
						if(data.content){
							var html = "";
							var rule2 = eval(data.content);
							for (var o in rule2) {
								var top = 0.8*Math.random();
								var speed = 8*(Math.random()+1);
								var delay = 7*(Math.random()+1);
//								html=html+"<div onClick='javascript:window.location.href=\""+rule2[o].source_url+"\" ' class='golden1 fly1 fly-moveFromLeft'";
//								html=html+"style='z-index:1600;top:"+top*100+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
//								html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;background-color:#"+rule[o].background_color+";' >";
//								html=html+"<div class='border_span_img'>";
//								html=html+"<img src='/ws"+rule2[o].pic_url+"'>";
//								html=html+"<span  class='chat-content'>"+rule2[o].title+"</span>";
//								html=html+"</div>";
//								html=html+"</div>";
								if(rule2[o].color==""||rule2[o].color==null){
									html = html+"<ul class='golden fly fly-moveFromLeft'";
								}else{
									html = html+"<ul class='"+rule2[o].color+" fly fly-moveFromLeft'";
								}
								if(rule2[o].group_id!=null&&rule2[o].group_id!=0){
									html = html+" onClick=\"toJSSpecialUrl(this,\'"+rule2[o].group_id+"\')\" ";
								}else{
									html = html+" onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\" ";
								}
								
								html=html+"style='z-index:1600;top:"+top*100+"%;animation-delay:"+delay+"s;-webkit-animation-delay:"+delay+"s;";
								html=html+"animation-duration:"+speed+"s;-webkit-animation-duration:"+speed+"s;' >";
								html=html+"<li><img src='/ws"+rule2[o].pic_url+"'></li>";
								html = html+"<li><span class='chat-content'>"+rule2[o].title+"</span></li>";
//								if(rule2[o].group_id!=null&&rule2[o].group_id!=0){
//									html = html+"<li onClick=\"toJSSpecialUrl(this,\'"+rule2[o].group_id+"\')\" ><span class='chat-content'>"+rule2[o].title+"</span></li>";
//								}else{
//									html = html+"<li onClick=\"toSpecialUrl(this,\'"+rule2[o].source_url+"\')\"><span class='chat-content'>"+rule2[o].title+'</span></li>';
//								}
								html=html+"<li></li>";
								html=html+"</ul>";
								}
							$(".chat").append(html);
						}
						
					}else if(data.error=="4004"){
						showMsg("您已经被管理员禁言了~");
					}else if(data.error=="2002"){
						showMsg("您的吐槽有敏感词汇，无法发送~");
					}else{
						showMsg("吐槽失败~");
					}
				},"json");
			}
			function getBLen(str) {
			  if (str == null) return 0;
			  if (typeof str != "string"){
			    str += "";
			  }
			  return str.replace(/[^\x00-\xff]/g,"00").length;
			}
			
			function addClickAd(id,url){
				var posturl="/ws/index.php?g=mobile&m=chat&a=addClickAd";
				var data = {
					'id':id
				}
				$.post(posturl,data,function(res){
					if(res.error==0){
						window.location.href=url;
					}
				},'json')
			}
			
			function getSpecialAdJSON(){
				var adNow = now/1000;//秒计算
				for(var o in specialAd){
					var update = specialAd[o].ad_starttime;
					if(update>=adNow){
						setTimeout(function(){
							updateAd(specialAd[o],specialAd[o].ad_place);
							setTimeout(function(){
								updateAd(carouselAd[specialAd[o].ad_place-1],specialAd[o].ad_place);
							},(specialAd[o].ad_endtime-specialAd[o].ad_starttime)*1000);
						},(update-adNow)*1000);
					}else{
						updateAd(specialAd[o],specialAd[o].ad_place);
						setTimeout(function(){
							updateAd(carouselAd[specialAd[o].ad_place-1],specialAd[o].ad_place);
						},(specialAd[o].ad_endtime-adNow)*1000);
					}
				}
			}
			function updateAd(Ad,place){
				$("#carousel_a_"+place).attr("onclick","addClickAd('"+Ad.id+"','"+Ad.url+"')");
				$("#carousel_img_"+place).attr("src","/ws"+Ad.pic_path);
				$("#carousel_h1_"+place).html(Ad.title);
				var   d=new  Date(Ad.created*1000);
				var time = formatDate(d);
				var html ="记者："+Ad.description+"<span class='report-time'>"+time+"</span>";
				$("#carousel_p_"+place).html(html);
			}
			
			function   formatDate(now)   {     
	              var   year=now.getFullYear();     
	              var   month=now.getMonth()+1;     
	              var   date=now.getDate();     
	              return   year+"-"+month+"-"+date;     
            }
			function toSpecialUrl(params,url){
				$(params).parent().addClass('clicked');
				window.location.href=url;
			}
			
			function toJSSpecialUrl(params,group_id,url){
				if(isSend){
					return;
				}
				isSend =true;
				$(params).parent().addClass('clicked');
				if(group_id=='null'||group_id==null||group_id==undefined||group_id==0){
					window.location.href=url;
				}else{
					//根据id获取
					var url="index.php?g=mobile&m=chat&a=getBox";
					var data = {
							group_id:group_id
					} 
					$.post(url,data,function(res){
						if(res.error ==1){//第一次
							doSomeThingFortype(res.type,res);
						}else if(res.error==2){
							doSomeThingFortypeSercont(res.type,res);
						}else{
							showMsg(res.content);
						}
						isSend = false;
					},"json")
				}
			}
			//第一次
			function doSomeThingFortype(type,res){
				$("#prize").addClass('hide');
				$("#noPrize").addClass('hide');
				$("#info").addClass('hide');
				$("#warn").addClass('hide');
				$('.modal_panel_inner a').unbind("click");
				$("#name").val('');//制空
				$("#phone").val('');
				touch.on('.modal_zzc', 'doubletap', function(e){
				    e.stopPropagation();
					$('.modal').modal('hide');
				});
				$('.modal').modal({
					show : true,
					backdrop : false
				});
				if(type==1){//信息框
					if(res.box.is_extend_links==1){//外链
						$('#info a').click(function(e){
							e.preventDefault();
							//保存信息
							saveInfo(res.box.url,res.box.group_id,res.box.id);
							//window.location.href=res.box.url;
						})
					}else{
						$("#info a").click(function(e){
							e.stopPropagation();
							saveInfo(false,res.box.group_id,res.box.id);
							//$(this).parent('.modal_panel').addClass('hide');
						})
					}
					//$('#info_img').attr('src',res.box.pic);
					$("#info").removeClass('hide');
				}else if(type==2){
					if(res.prize!=0){//有奖
						$("#prize_name").html(res.box.name);
//						$("#prize_name").html("恭喜你，获取"+res.box.name);
						$("#prize_img").attr("src","/ws"+res.box.pic);
						if(res.box.is_extend_links==1){//外链
							$('#prize a').click(function(e){
								e.preventDefault();
								$('.modal').modal('hide');
								//saveInfo(res.box.url);
								window.location.href=res.box.url;
							})
						}else{
							$("#prize a").click(function(e){
								e.stopPropagation();
								$('.modal').modal('hide');
								//$(this).parent('.modal_panel').addClass('hide');
							})
						}
						$("#prize").removeClass('hide');
					}else{//无奖
//						$("#noPrize_img").attr("src","/ws"+res.box.pic);
						$("#noPrize a").click(function(e){
							e.stopPropagation();
							//$(this).parent('.modal_panel').addClass('hide');
							$('.modal').modal('hide');
						})
						$("#noPrize").removeClass('hide');
					}
				}else if(type==3){
					if(res.prize!=0){//有奖
						$("#prize_name").html(res.box.name);
						$("#prize_img").attr("src","/ws"+res.box.pic);
						$('#prize a').click(function(e){//跳转至信息框
							e.preventDefault();
							$("#prize").addClass('hide');
							$("#info").removeClass('hide');
						});
						$("#info a").click(function(e){
							if(res.box.is_extend_links==1){
								e.preventDefault();
								saveInfo(res.box.url,res.box.group_id,res.info.id);
								//window.location.href=res.box.url;
							}else{
								e.stopPropagation();
								saveInfo(false,res.box.group_id,res.info.id);
								//$(this).parent('.modal_panel').addClass('hide');
							}
						});
						$("#prize").removeClass('hide');
					}else{//无奖
//						$("#noPrize_img").attr("src","/ws"+res.box.pic);
						$("#noPrize a").click(function(e){
							e.stopPropagation();
							$('.modal').modal('hide');
							//$(this).parent('.modal_panel').addClass('hide');
						})
						$("#noPrize").removeClass('hide');
					}
				}
			}
			function doSomeThingFortypeSercont(type,res){
				$("#prize").addClass('hide');
				$("#noPrize").addClass('hide');
				$("#info").addClass('hide');
				$("#warn").addClass('hide');
				$('.modal_panel_inner a').unbind("click");
				$("#name").val('');//制空
				$("#phone").val('');
//				$('.modal_zzc').click(function(e){
//		    		e.stopPropagation();
//		    		$('.modal').modal('hide');
//		    	});
				touch.on('.modal_zzc', 'doubletap', function(e){
				    e.stopPropagation();
					$('.modal').modal('hide');
				});
				$('.modal').modal({
					show : true,
					backdrop : false
				});
				if(type==1){
					$("#warn_content").html(res.content);
					$("#warn a").click(function(e){
						e.stopPropagation();
//						if(res.box.is_extend_links==1){//外链
//							if(res.box.url==null||res.box.url=="null"||res.box.url==undefined){
//								$('.modal').modal('hide');
//							}else{
//								window.location.href=res.box.url;
//							}
//						}else{
							//$(this).parent('.modal_panel').addClass('hide');
							$('.modal').modal('hide');
//						}
					})
					$("#warn").removeClass('hide');
				}else if(type==2){
					if(res.prize!=0){//有奖
						$("#prize_name").html(res.box.name);
//						$("#prize_name").html("恭喜你，获取"+res.box.name);
						$("#prize_img").attr("src","/ws"+res.box.pic);
						if(res.box.is_extend_links==1){//外链
							$('#prize a').click(function(e){
								e.preventDefault();
								//$(this).parent('.modal_panel').addClass('hide');
								$('.modal').modal('hide');
								if(res.box.url==null||res.box.url=="null"||res.box.url==undefined){
									
								}else{
									window.location.href=res.box.url;
								}
								
							})
						}else{
							$("#prize a").click(function(e){
								e.stopPropagation();
								//$(this).parent('.modal_panel').addClass('hide');
								$('.modal').modal('hide');
							})
						}
						$("#prize").removeClass('hide');
					}else{//无奖
//						$("#noPrize_img").attr("src","/ws"+res.box.pic);
						$("#noPrize a").click(function(e){
							e.stopPropagation();
							//$(this).parent('.modal_panel').addClass('hide');
							$('.modal').modal('hide');
						})
						$("#noPrize").removeClass('hide');
					}
				}else if(type==3){
					if(res.statusType==1){//个人信息框（完结）
						$("#warn_content").html(res.content);
						$("#warn a").click(function(e){
							e.stopPropagation();
//							if(res.box.is_extend_links==1){//外链
//								if(res.box.url==null||res.box.url=="null"||res.box.url==undefined){
//									$('.modal').modal('hide');
//								}else{
//									window.location.href=res.box.url;
//								}
//							}else{
								//$(this).parent('.modal_panel').addClass('hide');
								$('.modal').modal('hide');
//							}
						})
						$("#warn").removeClass('hide');
					}else if(res.statusType==2){//领奖
						if(res.prize!=0){//有奖
							$("#prize_name").html(res.box.name);
							$("#prize_img").attr("src","/ws"+res.box.pic);
							$('#prize a').click(function(e){//跳转至信息框
								e.preventDefault();
								$("#prize").addClass('hide');
								$("#info").removeClass('hide');
							});
							$("#info a").click(function(e){
								if(res.box.is_extend_links==1){
									e.preventDefault();
									saveInfo(res.box.url,res.box.group_id,res.info.id);
									//window.location.href=res.box.url;
								}else{
									e.stopPropagation();
									saveInfo(false,res.box.group_id,res.info.id);
									//$(this).parent('.modal_panel').addClass('hide');
								}
							});
							$("#prize").removeClass('hide');
						}else{//无奖
//							$("#noPrize_img").attr("src","/ws"+res.box.pic);
							$("#noPrize a").click(function(e){
								e.stopPropagation();
								//$(this).parent('.modal_panel').addClass('hide');
								$('.modal').modal('hide');
							})
							$("#noPrize").removeClass('hide');
						}
						
					}else if(res.statusType==3){
//						$("#noPrize_img").attr("src","/ws"+res.box.pic);
						$("#noPrize a").click(function(e){
							e.stopPropagation();
							//$(this).parent('.modal_panel').addClass('hide');
							$('.modal').modal('hide');
						})
						$("#noPrize").removeClass('hide');
					}
					
				}
			}
			function saveInfo(url,group_id,status_id){
				var saveUrl = "index.php?g=mobile&m=chat&a=saveInfo";
				var name = $("#name").val();
				var phone = $("#phone").val();
				if(name==""){
					showMsg("请填写姓名");
					return false;
				}
				if(phone==""){
					showMsg("请填写电话号码");
					return false;
				}
				var date = {
						group_id:group_id,
						status_id:status_id,
						name:name,
						phone:phone
				}
				$.post(saveUrl,date,function(res){
					if(res.error==1){//保存成功
						if(url){
							showMsg2(res.content,url);
						}else{
							showMsg(res.content);
							//$("#info").parent('.modal_panel').addClass('hide');
							$('.modal').modal('hide');
						}
					}else{
						showMsg(res.content);
					}
				},"json");
			}
			function showMsg2(msg,url){
				$('a.alert-btn').unbind("click");
	    		$("#msg").text(msg);
				$('#alert2').show();
				$('.mask_zzc').show();
				$('a.alert-btn').click(function (e) {
					if(url==null||url=="null"||url==undefined){
						$('a.alert-btn').unbind("click");
						$('a.alert-btn').click(function (e) {
				    		$('div.alert').hide();
				    		$('.mask_zzc').hide();
				    	});
					}else{
						window.location.href=url;
					}
		    		$('div.alert').hide();
		    		$('.mask_zzc').hide();
		    	});
	    	}
			